package com.itheima.mall.web.pms;

import com.itheima.mall.dto.BrandDto;
import com.itheima.mall.pojo.pms.Brand;
import com.itheima.mall.service.pms.BrandService;
import com.itheima.mall.vo.PageResult;
import com.itheima.mall.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 添加品牌
     * @param brandDto
     * @return
     */
    @PostMapping("/create")
    public R  brandCreate(@RequestBody BrandDto brandDto){
        brandService.brandCreate(brandDto);
        return R.succeed(null,"操作成功");
    }

    /**
     * 批量删除品牌
     * @param ids
     * @return
     */
    @PostMapping("/delete/batch")
    public R deleteBatch(@RequestParam Integer[] ids){
        brandService.deleteBatch(ids);
        return R.succeed(null,"操作成功");
    }

    /**
     * 删除品牌
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public R deleteBrand(@PathVariable("id") Integer id){
        brandService.deleteBrand(id);
        return R.succeed(null,"操作成功");
    }

    /**
     * 根据品牌名称分页获取品牌列表
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("/list")
    public R brandList(@RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String keyword){
        PageResult pr = brandService.brandList(pageNum,pageSize,keyword);
        return R.succeed(pr,"操作成功");
    }

    /**
     * 获取全部品牌列表
     * @return
     */
    @GetMapping("/listAll")
    public R brandListAll(){
        List<Brand> list = brandService.brandListAll();
        return R.succeed(list,"操作成功");
    }

    /**
     * 批量更新厂家制造商状态
     * @return
     */
    @PostMapping("/update/factoryStatus")
    public R updateFactoryStatus(@RequestParam Integer factoryStatus,
                                 @RequestParam Integer[] ids){
        brandService.updateFactoryStatus(ids,factoryStatus);
        return R.succeed(null,"操作成功");

    }

    /**
     * 批量更新显示状态
     * @param showStatus
     * @param ids
     * @return
     */
    @PostMapping("/update/showStatus")
    public R updateShowStatus(@RequestParam Integer showStatus,
                              @RequestParam Integer[] ids){
        brandService.updateShowStatus(ids,showStatus);
        return R.succeed(null,"操作成功");

    }

    /**
     * 更新品牌
     * @param id
     * @param brandDto
     * @return
     */
    @PostMapping("/update/{id}")
    public R update(@PathVariable("id") Integer id,
                        @RequestBody BrandDto brandDto){
        brandService.update(id,brandDto);
        return R.succeed(null,"操作成功");
    }

    /**
     * 根据编号查询品牌信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R select(@PathVariable("id") Integer id){
        Brand brand = brandService.select(id);
        return R.succeed(brand,"操作成功");
    }
}
